﻿/*
 * Created by SharpDevelop.
 * User: Andrew
 * Date: 05/05/2013
 * Time: 01:38
 * 
 * To change this template use Tools | Options | Coding | Edit Standard Headers.
 */
using System;
using System.Drawing;
using System.IO;

using RRRSRoguelike.Enums;
using RRRSRoguelike.Helpers;
using RRRSRoguelike.Helpers.Visualizer;
using RRRSRoguelike.Managers;

namespace RRRSRoguelike.Screens
{
	/// <summary>
	/// Description of ProfileScreen.
	/// </summary>
	public class ProfileScreen:Screen
	{
		Panel MainPanel;

        #region Constructors
		
        /// <summary>
        /// Gets a profile name from user.
        /// </summary>
        public ProfileScreen()
		{
			PanelList.Add(new Panel(new Point(4, 3),
				Visualizer.GetScreenWidth() - 9, Visualizer.GetScreenHeight() - 6));
			MainPanel = PanelList[0];
		}

        #endregion

        #region Methods

        /// <summary>
        /// Show screen
        /// </summary>
        public override void Show()
		{
			Clear();
			this.MainPanel.Clear();
			MainPanel.Draw();
			
			// Check if the user already has a profile.  Later they can edit from the option menu 
			if(Properties.Settings.Default.Profile == "-1")
			{
				//HACK: should be a culture string
				this.MainPanel.Write("Please enter your name: ", 0, ConsoleColor.White, TextAlignment.Multi);
				
				
	
	            GetNameFromUser();
			}
			else
			{
				//TODO: this is where we should load the profile
				ApplicationManager.Instance.Profile.Name = Properties.Settings.Default.Profile;
				
				ApplicationManager.Instance.Profile.Load();
			}
			
			
			this.MainPanel.Clear();
			//HACK: should be a culture string
			this.MainPanel.Write("Welcome " + ApplicationManager.Instance.Profile.Name);

			WaitKey();

			ApplicationManager.Instance.SoundManager.PlaySound(SoundList.Pluck.ToString());


		}

		private void GetNameFromUser()
		{
			//HACK: hard coded a quick fix to get the seed input in the right place
			//Better to have a formal way to aks questions
			Console.SetCursorPosition(35,5);
			
			string input = Console.ReadLine();
			
			if (input.Length > 10) 
			{
				GameManager.Instance.SoundManager.PlaySound(SoundList.Pluck.ToString());
				MainPanel.Clear();
				//HACK: should be a culture string
				MainPanel.Write("Name should be no more than than 10 characters");
				WaitKey();
	            Show();
			}

			//Set the profile for this play through
			ApplicationManager.Instance.Profile.Name = input;
			
			//Save users profie to settings.
			Properties.Settings.Default.Profile = ApplicationManager.Instance.Profile.Name;
			Properties.Settings.Default.Save();

				
		}
		#endregion
	}
}
